<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
test(() => {
    assert_not_equals(window.internals, undefined,
        'This test requires window.internals to access clipboard');

    // TODO(yosin): We should consoliate "paste-line-endings-00[1-5].html" here.

    assert_selection(
        [
            '<div contenteditable>',
                '<div>line one^<br>l|ine two</div>',
            '</div>',
        ].join(''),
        selection => {
            selection.document.execCommand('copy');
            selection.document.execCommand('paste');
        },
        [
            '<div contenteditable>',
                '<div>line one<br>l|ine two</div>',
            '</div>',
        ].join(''),
        '6 Paste with BR');

    assert_selection(
        [
            '<div contenteditable>',
                'line one^<div>l|ine two</div>',
            '</div>',
        ].join(''),
        selection => {
            selection.document.execCommand('copy');
            selection.document.execCommand('paste');
        },
        [
            '<div contenteditable>',
                'line one<div>l|ine two</div>',
            '</div>',
        ].join(''),
        '7 Paste with DIV');

    assert_selection(
        [
            '<div contenteditable>',
                '<div>line one^</div><div>l|ine two</div>',
            '</div>',
        ].join(''),
        selection => {
            selection.document.execCommand('copy');
            selection.document.execCommand('paste');
        },
        [
            '<div contenteditable>',
                '<div>line one</div><div>l|ine two</div>',
            '</div>',
        ].join(''),
        '8 Paste into crossing DIV');

    assert_selection(
        [
            '<div contenteditable>',
                '<div>line one^<div>l|ine two</div></div>',
            '</div>',
        ].join(''),
        selection => {
            selection.document.execCommand('copy');
            selection.document.execCommand('paste');
        },
        [
            '<div contenteditable>',
                'line one<br><div>l|ine two<br></div>',
            '</div>',
        ].join(''),
        '9 Paste into nested DIV');

    assert_selection(
        [
            '<div contenteditable>',
                '<div><div>line one^</div>l|ine two</div>',
            '</div>',
        ].join(''),
        selection => {
            selection.document.execCommand('copy');
            selection.document.execCommand('paste');
        },
        [
            '<div contenteditable>',
                '<div><div>line one</div>l|ine two</div>',
            '</div>',
        ].join(''),
        '10 Paste inside DIV');
}, 'Copying and pasting selection starting at end of paragraph');
</script>
